package com.hunttown.mes.common.qcloud.qcloudcos;

import com.hunttown.mes.common.utils.DateConvertUtils;
import com.hunttown.mes.common.utils.StringUtils;

import java.util.Date;
import java.util.Objects;

/**
 * 腾讯云对象存储参数配置
 * created by wangjunfu on 2019-09-18
 */
public class CosConstants {

    //region 获取访问地址：访问地址前缀（动态）{0}桶名称；{1}地区；{2}唯一key
    public static String getPreFixedUrl(String bucket, String region, String onlykey) {
        return String.format("https://%s.cos.%s.myqcloud.com/%s", bucket, region, onlykey);
    }
    //endregion

    //region 获取文件存储前缀
    public static final String ImagePrefix = "images/";    //日常图片(经常使用，不建议清理)
    public static final String FilePrefix = "files/" + DateConvertUtils.getDateFolder(new Date()) + "/";      //日常文件(长时间可清理)
    public static final String RepairPrefix = "repair/" + DateConvertUtils.getDateFolder(new Date()) + "/";   //维修资源(长时间可清理)
    public static final String SafetyPrefix = "safety/" + DateConvertUtils.getDateFolder(new Date()) + "/";   //安全资源(不建议清理)
    public static final String NewsPrefix = "news/" + DateConvertUtils.getDateFolder(new Date()) + "/";       //新闻(长时间可清理)

    //文件要保存到image中的项目
    public static String getStorageFolder(String key) {
        String folder = "files";

        if (StringUtils.isBlank(key) || Objects.equals(key, "--")) {
            return folder;
        }

        switch (key.toLowerCase()) {
            case "jishiben":        //记事本
            case "huiyijiyao":      //会议纪要
            case "gongsirongyu":    //公司荣誉
            case "shouyehuandeng":  //首页幻灯
            case "lianxiwomen":     //联系我们
            case "hezuohuoban":     //合作伙伴
            case "kehuanli":        //客户案例
            case "gongsihuodong":   //公司活动
            case "fuwuxiangmu":     //服务项目
            case "cheliangzhanshi": //车辆展示
            case "guanyuwomen":     //关于我们
            case "tongzhi":         //公司通知
                folder = "images";
                break;
        }

        return folder;
    }
    //endregion
}
